package mappedClass;

import javax.persistence.AttributeOverride;
import javax.persistence.AttributeOverrides;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;


@Entity
@Table(name = "teamtask", catalog = "test", uniqueConstraints = @UniqueConstraint(columnNames = {
		"teamId", "taskId" }))
public class TeamTask implements java.io.Serializable {

	private TeamTaskId id;
	private Task task;
	private Team team;

	public TeamTask() {
	}

	public TeamTask(TeamTaskId id, Task task, Team team) {
		this.id = id;
		this.task = task;
		this.team = team;
	}
	
	@EmbeddedId
    @AttributeOverrides({
                    @AttributeOverride(name = "taskId", column = @Column(name = "taskId", nullable = false)),
                    @AttributeOverride(name = "teamId", column = @Column(name = "teamId", nullable = false)) })
    public TeamTaskId getId() {
            return this.id;
    }

    public void setId(TeamTaskId id) {
            this.id = id;
    }
	
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "taskId", nullable = false, insertable = false, updatable = false)
	public Task getTask() {
		return this.task;
	}

	public void setTask(Task task) {
		this.task = task;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "teamId", nullable = false, insertable = false, updatable = false)
	public Team getUser() {
		return this.team;
	}

	public void setUser(Team team) {
		this.team = team;
	}

	@Override
	public String toString() {
		return "TeamTask [task=" + task + ", team=" + team;
	}

}

